<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="商家表" prop="sellerId">
									<el-input v-model="form.sellerId" placeholder="请输入商家表" clearable></el-input>
								</el-form-item>
								<el-form-item label="评论数量" prop="commentCount">
									<el-input v-model="form.commentCount" placeholder="请输入评论数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="好评率 100%" prop="commentHp">
									<el-input v-model="form.commentHp" placeholder="请输入好评率 100%" clearable></el-input>
								</el-form-item>
								<el-form-item label="好评数量" prop="commentHpsl">
									<el-input v-model="form.commentHpsl" placeholder="请输入好评数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="中差评数量" prop="commentZcsl">
									<el-input v-model="form.commentZcsl" placeholder="请输入中差评数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="总星数量" prop="commentXjzl">
									<el-input v-model="form.commentXjzl" placeholder="请输入总星数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="收藏人数" prop="collectionCount">
									<el-input v-model="form.collectionCount" placeholder="请输入收藏人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="称赞人数" prop="tagCount">
									<el-input v-model="form.tagCount" placeholder="请输入称赞人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="历史浏览人数" prop="lookCount">
									<el-input v-model="form.lookCount" placeholder="请输入历史浏览人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="总交易额" prop="turnover">
									<el-input v-model="form.turnover" placeholder="请输入总交易额" clearable></el-input>
								</el-form-item>
								<el-form-item label="余额" prop="balance">
									<el-input v-model="form.balance" placeholder="请输入余额" clearable></el-input>
								</el-form-item>
								<el-form-item label="经度" prop="longitude">
									<el-input v-model="form.longitude" placeholder="请输入经度" clearable></el-input>
								</el-form-item>
								<el-form-item label="纬度" prop="latitude">
									<el-input v-model="form.latitude" placeholder="请输入纬度" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系人" prop="linkUser">
									<el-input v-model="form.linkUser" placeholder="请输入联系人" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系座机电话" prop="landline">
									<el-input v-model="form.landline" placeholder="请输入联系座机电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="手机" prop="phone">
									<el-input v-model="form.phone" placeholder="请输入手机" clearable></el-input>
								</el-form-item>
								<el-form-item label="邮箱" prop="email">
									<el-input v-model="form.email" placeholder="请输入邮箱" clearable></el-input>
								</el-form-item>
								<el-form-item label="商家详细地址" prop="address">
									<el-input v-model="form.address" placeholder="请输入商家详细地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="无线名" prop="wifiName">
									<el-input v-model="form.wifiName" placeholder="请输入无线名" clearable></el-input>
								</el-form-item>
								<el-form-item label="无线密码" prop="wifiPwd">
									<el-input v-model="form.wifiPwd" placeholder="请输入无线密码" clearable></el-input>
								</el-form-item>
								<el-form-item label="限制链接人数" prop="wifiLimit">
									<el-input v-model="form.wifiLimit" placeholder="请输入限制链接人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="水印" prop="watermark">
									<el-input v-model="form.watermark" placeholder="请输入水印" clearable></el-input>
								</el-form-item>
								<el-form-item label="推广编码" prop="promoteNum">
									<el-input v-model="form.promoteNum" placeholder="请输入推广编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="推广说明" prop="promoteMsg">
									<el-input v-model="form.promoteMsg" placeholder="请输入推广说明" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import sellerAPI from '@/api/seller/sellerDetails';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					sellerId: "",
					commentCount: "",
					commentHp: "",
					commentHpsl: "",
					commentZcsl: "",
					commentXjzl: "",
					collectionCount: "",
					tagCount: "",
					lookCount: "",
					turnover: "",
					balance: "",
					longitude: "",
					latitude: "",
					linkUser: "",
					landline: "",
					phone: "",
					email: "",
					address: "",
					wifiName: "",
					wifiPwd: "",
					wifiLimit: "",
					watermark: "",
					promoteNum: "",
					promoteMsg: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await sellerAPI.sellerDetails.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.sellerId = data.sellerId;
				this.form.commentCount = data.commentCount;
				this.form.commentHp = data.commentHp;
				this.form.commentHpsl = data.commentHpsl;
				this.form.commentZcsl = data.commentZcsl;
				this.form.commentXjzl = data.commentXjzl;
				this.form.collectionCount = data.collectionCount;
				this.form.tagCount = data.tagCount;
				this.form.lookCount = data.lookCount;
				this.form.turnover = data.turnover;
				this.form.balance = data.balance;
				this.form.longitude = data.longitude;
				this.form.latitude = data.latitude;
				this.form.linkUser = data.linkUser;
				this.form.landline = data.landline;
				this.form.phone = data.phone;
				this.form.email = data.email;
				this.form.address = data.address;
				this.form.wifiName = data.wifiName;
				this.form.wifiPwd = data.wifiPwd;
				this.form.wifiLimit = data.wifiLimit;
				this.form.watermark = data.watermark;
				this.form.promoteNum = data.promoteNum;
				this.form.promoteMsg = data.promoteMsg;
			}
		}
	}
</script>
<style>
</style>
